import { post } from '.'

// 聊天相关API
export async function chatMessageAPI(platform: string, model: string, message: string) {
  return post('/ai/chat/text', {
    platform,
    model,
    message,
  })
}

export async function chatImageAPI(platform: string, model: string, prompt: string, size: string) {
  return post('/ai/create/image', {
    platform,
    model,
    prompt,
    size,
  })
}

// 用户认证相关API
export interface LoginRequest {
  username: string
  password: string
  remember?: boolean
}

export interface LoginResponse {
  token: string
  user: {
    id: number
    uuid: string
    username: string
    email: string
    avatarUrl?: string
    subscriptionType: string
  }
}

export interface RegisterRequest {
  username: string
  email: string
  password: string
  confirmPassword: string
}

export interface RegisterResponse {
  user: {
    id: number
    uuid: string
    username: string
    email: string
  }
}

// 登录API
export async function loginAPI(data: LoginRequest): Promise<LoginResponse> {
  return post<LoginRequest, LoginResponse>('/auth/login', data)
}

// 注册API
export async function registerAPI(data: RegisterRequest): Promise<RegisterResponse> {
  return post<RegisterRequest, RegisterResponse>('/aichat/users/register', data)
}

// 退出登录API
export async function logoutAPI(): Promise<void> {
  await post('/aichat/users/logout')
}

// 获取用户信息API
export async function getUserInfoAPI() {
  return post('/aichat/users/profile')
}

// 刷新Token API
export async function refreshTokenAPI(): Promise<{ token: string }> {
  return post<unknown, { token: string }>('/aichat/users/refresh-token')
}

// 忘记密码API
export async function forgotPasswordAPI(email: string): Promise<void> {
  await post('/aichat/users/forgot-password', { email })
}

// 重置密码API
export async function resetPasswordAPI(token: string, password: string): Promise<void> {
  await post('/aichat/users/reset-password', { token, password })
}

// 第三方登录API
export async function oauthLoginAPI(provider: string, code: string): Promise<LoginResponse> {
  return post<{ code: string }, LoginResponse>(`/aichat/users/oauth/${provider}`, { code })
}

// 获取第三方登录URL
export async function getOauthUrlAPI(provider: string, redirectUri?: string): Promise<{ url: string }> {
  return post<{ redirectUri?: string }, { url: string }>(`/aichat/users/oauth/${provider}/url`, { redirectUri })
}
